import { dom } from "../../lib/mve-DOM/index";
import { EOChild, fragment } from "../../lib/mve/childrenBuilder";

export function isInPage(node) {
	return (node === document.body) ? false : document.body.contains(node);
}


function onDomLog(v, s: string) {
	if (isInPage(v)) {
		console.log(s, "在DOM上")
	} else {
		console.error(s, "不在DOM上")
	}
}
export function testDomNode(): EOChild<Node> {
	let firstDIV: HTMLDivElement
	let secondDIV: HTMLDivElement
	return fragment({
		init() {
			console.log("childLife初始化")
			return function () {
				console.log("childLife销毁")
			}
		},
		children: [
			dom({
				type: "div",
				init(a) {
					firstDIV = a
					onDomLog(firstDIV, "第一个初始化")
					return () => {
						onDomLog(firstDIV, "第一个销毁")
					}
				}
			}),
			dom({
				type: "div",
				init(b) {
					secondDIV = b
					onDomLog(secondDIV, "第二个初始化")
					return function () {
						onDomLog(secondDIV, "第二个销毁")
					}
				}
			})
		]
	})
}